<?php
/**
 * @Author: king
 * @Last Modified by:   king
 * Date: 2018/6/6
 * Time: 17:38
 */
namespace App\Models\Api;
use App\Exceptions\ApiException;
use App\Models\Api\Base;
use Illuminate\Database\Eloquent\Model;
use Cache;

class AppVersion extends Base
{
    protected $table = 'version';

    public function getVersionData($map = [])
    {
        $data = false;
        // if(intval($this->cache_on) >= 1 && Cache::has('version_'.$map['type']))
        // {
        //     $data = Cache::get('version_'.$map['type']);
        // }

        if($data === false){
            try{
                $data = $this->where(['status'=>1,'type'=>$map['type']])
                    ->orderBy('id','DESC')->first(['version','version_name','url','update_content','force','is_astro_data_from_local','debug']);

                Cache::set('version_'.$map['type'],$data,86400 * 3);

            }catch (\Exception $e){
                $data = [];
            }
        }
        return $data;
    }
}
